package com.gxa.insurance.controller;

import com.gxa.insurance.exception.BusinessException;
import com.gxa.insurance.pojo.Coupon;
import com.gxa.insurance.pojo.Customer;
import com.gxa.insurance.pojo.Exchange;
import com.gxa.insurance.service.ExchangeService;
import com.gxa.insurance.util.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author lijunlin
 * @date 2022/6/7
 */
@Api(value = "兑换码模块exchange相关api接口")
@RestController
@RequestMapping("/exchange")
@CrossOrigin
public class ExchangeController {
    @Autowired
    ExchangeService exchangeService;
    @ApiOperation(value = "兑换码添加的方法",produces = "body")
    @PostMapping("/addExchange")
    public Map addExchange(@RequestBody Exchange exchange){
        Integer integer = exchangeService.addExchange(exchange);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("兑换码添加成功");
        jsonResult.put("exchangeCodeId",integer);
        return jsonResult.getMap();
    }

    @ApiOperation(value = "分页查询所有兑换码的方法",produces = "body")
    @GetMapping("/selectByPage")
    public Map selectByPage(Integer currentPage,Integer pageSize){
        Map<String, Object> maps = exchangeService.selectByPage(currentPage, pageSize);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("查询所有数据成功");

        jsonResult.setData(maps);
        return jsonResult.getMap();
    }
    @ApiOperation(value = "根据Id查询兑换券的方法",produces = "query")
    @PostMapping("/selectById")
    public Map selectById(@RequestParam(value = "id",required = true,defaultValue = "1") Integer integer) throws Exception {
        Exchange exchange = exchangeService.selectById(integer);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("兑换码查询成功");
        jsonResult.setData(exchange);
        return jsonResult.getMap();
    }
    @ApiOperation(value = "兑换码修改的方法",produces = "body")
    @PostMapping("/updateExchange")
    public Map updateExchange( @RequestBody Exchange exchange) throws Exception {

        exchangeService.updateExchange(exchange);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("兑换码修改成功");
        return jsonResult.getMap();
    }
    @ApiOperation(value = "删除兑换码的方法",produces = "query")
    @PostMapping("/deleteExchange")
    public Map deleteExchange(@RequestParam(value = "id",required = true,defaultValue = "10") Integer integer){
        exchangeService.deleteExchange(integer);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("兑换码删除成功");
        return jsonResult.getMap();
    }

}
